﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Data.Accessor;
using NHibernate.Criterion;
using ZLCMS.Data.Model;
using System.Collections.Generic;
using ZLCMS.Business.Util;


namespace ZLCMS.Web.Example
{
    public partial class MemberLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //Forms身份验证初始化 
            FormsAuthentication.Initialize();

            String md5Code = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5").ToLower();
            ClientScriptManager csm = this.Page.ClientScript;

            //验证用户输入并得到登录用户，txtName是用户名称，txtPassword是登录密码 
            if (Session[GlobalSessionString.UserCheckCode] == null)
            {
                csm.RegisterStartupScript(this.GetType(), "error_tip", "alert('验证码过期，请重试。');", true);
                return;
            }

            if (Session[GlobalSessionString.UserCheckCode].ToString() != logincode.Text.Trim())
            {
                csm.RegisterStartupScript(this.GetType(), "error_tip", "alert('验证码输入错误，请重试。');", true);
                return;
            }

            if (UserKit.UserLoginMember(txtName.Text.Trim(), md5Code))
            {
                //转发到请求的页面
                Response.Redirect("~/MemberUser/Default.aspx");
            }
            else
            {
                csm.RegisterStartupScript(this.GetType(), "error_tip", "alert('用户名或密码错误！身份验证失败！');", true);
            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/");
        }
    }
}
